<?php

namespace App\Admin\Controllers;

use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Repositories\TongUserProfit;

class TongUserProfitController extends AdminController
{
    /**
     * 账单流水
     * @return Grid
     */
    public function grid(){
        return Grid::make(new TongUserProfit(['userInfo','orderInfo']),function(Grid $grid){
            $grid->column('id')->sortable();
            $grid->model()->orderBy('id', 'desc');
            //$grid->sortBy('id','desc');
            $grid->column('userInfo.nickname','用户名');
            $grid->column('money','金额');
            $grid->column('befor_money','到账前');
            $grid->column('after_money','到账后');
            $grid->column('status','状态')->view('admin.flow.fields.status');
            $grid->column('remark','说明')->view('admin.flow.fields.remark');
            $grid->column('created_at','创建时间');
            $grid->column('updated_at','更新时间')->sortable();

            //禁用掉了批量删除
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });

            });
            //$grid->tools('钱包充值');
            $grid->filter(function (Grid\Filter $filter) {
                // 更改为 panel 布局
                $filter->panel();
//                $filter->equal('id')->placeholder('请输入流水数据id')->width(3);
                $filter->equal('userInfo.mobile','会员手机号')->placeholder('请输入会员手机号')->width(3);
                $filter->equal('u_id','会员编号')->placeholder('请输入会员编号')->width(3);
                $filter->equal('status','状态')->select([1=>'已完成',2=>'未完成'])->placeholder('请选择到账状态')->width(3);
                $filter->equal('order_id','订单id')->placeholder('请输入订单id')->width(3);
                $filter->equal('orderInfo.order_no','HB订单编号')->placeholder('请输入HB订单编号')->width(3);
                $filter->in('type', '流水类型')->multipleSelect(['1' => '购买商品','2'=>'销售津贴','3'=>'门店津贴','4'=>'公司津贴','5'=>'管理津贴','6'=>'门店津贴','7'=>'培育津贴','8'=>'店铺培育','9'=>'钱包提现'])->width(3);
                $filter->day('created_at', '时间')->width(3);
            });

            // 禁用添加按钮
            $grid->disableCreateButton();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();

            });
            $grid->showActions(false);
            $grid->disableRowSelector();
            //启用导出功能
            $grid->export();
        });
    }
}
